import pandas as pd
from db.mongo_utils import query
from common_utils import pre_n_days

def account_data():
    users = []
    for user in query('data_works', 'redbook_user_info'):
        data = {
            '手机号': user['_id'],
            '昵称': user.get('user_name'),
            '博主类型': user.get('account_type'),
            '关注数': user.get('attent_number'),
            '粉丝数': user.get('follow_number'),
            '获赞收藏数': user.get('collection_like'),
            '违规历史': user.get('ban_history'),
            '主页': user.get('user_url'),
        }
        if user.get('is_banned'):
            data['当前状态是否异常'] = '是'
        else:
            data['当前状态是否异常'] = '否'
        users.append(data)
    df = pd.DataFrame(users)
    df.to_excel(f'{pre_n_days(0)}-小红书账号概况.xlsx', index=False)


if __name__ == '__main__':
    account_data()
